package top.dudu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import top.dudu.entity.ProductInfo;
import top.dudu.enums.ProductStatusEnum;
import top.dudu.repository.ProductInfoRepository;
import top.dudu.service.ProductInfoService;

import java.util.List;
import java.util.Optional;

/**
 * @author 嘟嘟
 * @date 2020-7-17 , 0017 9:17
 */
@Service
public class ProductInfoServiceImpl implements ProductInfoService {

    @Autowired
    ProductInfoRepository repository;

    @Override
    public ProductInfo findOne(String infoId) {
        Optional<ProductInfo> byId = repository.findById(infoId);
        if (byId.isPresent()) {
            return byId.get();
        }
        else return null;
    }

    @Override
    public List<ProductInfo> findUpAll() {
        return repository.findByProductStatus(ProductStatusEnum.UP.getCode());
    }

    @Override
    public Page<ProductInfo> findAll(Pageable pageable) {
        return repository.findAll(pageable);
    }

    @Override
    public ProductInfo save(ProductInfo productInfo) {
        return repository.save(productInfo);
    }
}
